# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >

_realname=pytz
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}" "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2019.3
pkgrel=1
pkgdesc="Cross platform time zone library for Python (mingw-w64)"
arch=('any')
url="https://pypi.python.org/pypi/pytz"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python2")
source=(https://pypi.io/packages/source/p/pytz/pytz-${pkgver}.tar.gz{,.asc})
sha256sums=('b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be'
            'SKIP')
validpgpkeys=('C7ECC365AB6F255E1EB9BA1701FA998FBAC6374A')

prepare() {
  cd "${srcdir}"
  for builddir in python{2,3}-build-${CARCH}; do
    rm -rf ${builddir} | true
    cp -r "pytz-${pkgver}" "${builddir}"
  done
}

build() {
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
      ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

check(){
  for pver in {2,3}; do
    msg "Python ${pver} test for ${CARCH}"
    cd "${srcdir}/python${pver}-build-${CARCH}/pytz/tests"
    MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
     ${MINGW_PREFIX}/bin/python${pver} test_tzinfo.py
  done
}

package_python3-pytz() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/python3-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -D LICENSE.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/python3-${_realname}/LICENSE
}

package_python2-pytz() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd "${srcdir}/python2-build-${CARCH}"

  # python 2 fix
  sed -i 's_#!/usr/bin/env python_#!/usr/bin/env python2_' pytz/tzfile.py

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1

  install -D LICENSE.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE
}

package_mingw-w64-i686-python2-pytz() {
  package_python2-pytz
}

package_mingw-w64-i686-python3-pytz() {
  package_python3-pytz
}

package_mingw-w64-x86_64-python2-pytz() {
  package_python2-pytz
}

package_mingw-w64-x86_64-python3-pytz() {
  package_python3-pytz
}
